package br.com.sgi.bean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;

import org.springframework.beans.factory.annotation.Autowired;

import br.com.sgi.service.RelatorioService;
import br.com.sgi.util.Constante;
import br.com.sgi.util.DateUtil;
import br.com.sgi.util.RelatorioUtil;

public class BaseRelatorio extends BaseView {
	
	@Autowired
	RelatorioService relatorioService;
	public Map<String, Object> parametros;
	
	
	private ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
	
	protected Map<String, Object> montaParametrosRelatorioConsulta() {
		Map<String, Object> parametros = new HashMap<String, Object>();
		String iconePath = servletContext.getRealPath(Constante.IMAGEM_FUNDO);
		parametros.put("ICONE", iconePath);
		parametros.put("dataDaPesquisa", DateUtil.getDateStr( new Date()));
		SimpleDateFormat hr = new SimpleDateFormat("HH:mm");  
		parametros.put("horaPesquisa",  hr.format(System.currentTimeMillis()));
		return parametros;
	}
	
	protected Map<String, Object> montaParametrosApenasTopo() {
		Map<String, Object> parametros = new HashMap<String, Object>();
		String iconePath = servletContext.getRealPath(Constante.IMAGEM_FUNDO);
		parametros.put("ICONE", iconePath);		
		parametros.put("dataDaPesquisa", DateUtil.getDateStr( new Date()));
		return parametros;
	}
	
	
	public void imprimir(List<?> objetos, String nomeRelatorio ) {
		relatorioService.gerarRelatorioPdf(objetos,
				montaParametrosRelatorioConsulta(), RelatorioUtil.getNomeRelatorioConsulta(),
				nomeRelatorio);
	}
	
	public void imprimir(List<?> objetos, String nomeRelatorio, Map<String, Object> paramentros ) {
		relatorioService.gerarRelatorioPdf(objetos,
				paramentros, RelatorioUtil.getNomeRelatorioConsulta(),
				nomeRelatorio);
	}
	

}
